package com.twohand.admin.Mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.twohand.admin.Entity.User;
import com.twohand.admin.Entity.UserRole;
import com.twohand.admin.Vo.UserListVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.List;

@Component
public interface  UserMapper extends BaseMapper<User> {
    @Select("select `user`.*,user_role.role_id from user LEFT JOIN user_role ON `user`.id = user_role.user_id order by user.id asc")
    List<UserListVo> selectAllUser();

    //查询是否存在appid对应的记录
    @Select("select * from user where openid = #{openid}")
    User selectByOpenid(String openid);

    @Select("select * from user where nickname = #{username} and pwd = #{password}")
    User selectByUserAPass(String username, String password);

    @Update("update user set login_time = #{localDateTime} where id = #{id}")
    Boolean updateLoginTime(Integer id,LocalDateTime localDateTime);

    List<UserListVo> queryAll(String nickname,String openid,Integer roleId);

    @Insert("insert into user_role(user_id,role_id) values(#{userId},#{roleId})")
    Integer insertUserAndRole(Integer userId, Integer roleId);
}
